{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "682f0242-329f-47a7-9026-25c8b4bf3c3d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入x：    3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "方法一：x = 3.0，y = 6.424305315239454\n",
      "方法二：x = 3.0，y = 6.424305315239454\n",
      "方法三：x = 3.0，y = 6.424305315239454\n"
     ]
    }
   ],
   "source": [
    "from  math import *\n",
    "x=float(input(\"请输入x：   \"))\n",
    "#  方法一：利用“单分支语句”实现\n",
    "if (x >= 0):   y = (x * x - 3 * x) / (x + 1) + 2 * pi + sin(x)\n",
    "if (x < 0):    y = log(-5 * x) + 6 * sqrt(abs(x) + pow(e, 4)) - pow(x + 1, 3)\n",
    "print(str.format(\"方法一：x = {0}，y = {1}\", x, y))\n",
    "#  方法二：利用“双分支结构”实现\n",
    "if (x >= 0):  y = (x * x - 3 * x) / (x + 1) + 2 * pi + sin(x)\n",
    "else:    y = log(-5 * x) + 6 * sqrt(abs(x) + pow(e, 4)) - pow(x + 1, 3)\n",
    "print(str.format(\"方法二：x = {0}，y = {1}\", x, y))\n",
    "#  方法三：利用“条件运算符”实现\n",
    "y =  (x * x - 3 * x) / (x + 1) + 2 * pi + sin(x) if (x >= 0) else log(-5 * x) + 6 * sqrt(abs(x) + pow(e, 4)) - pow(x + 1, 3)\n",
    "print(str.format(\"方法三：x = {0}，y = {1}\", x, y))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a424dbf-2a96-46c7-b2f4-6c6367dade52",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
